from sqlalchemy.orm import DeclarativeBase, declarative_base, relationship
from sqlalchemy import Column, Integer, String, Boolean, TIMESTAMP, ForeignKey, BIGINT
from datetime import datetime, timedelta, timezone






class Base(DeclarativeBase):
    pass
# 或者使用declarative_base()
#Base = declarative_base()

class User(Base):
    __tablename__ = "users"  # 用户表

    id: int = Column(Integer, primary_key=True, index=True)
    name: str = Column(String(255), unique=True, nullable=False)  # 唯一，用于登录
    nick_name: str = Column(String(255), nullable=False)   # 显示名称
    password_hash: str = Column(String(255), nullable=False)
    create_at: TIMESTAMP = Column(TIMESTAMP, default=datetime.now(timezone.utc), nullable=False)
    is_active: bool = Column(Boolean, default=True)



class New(Base):
    __tablename__ = "news"
    id: int = Column(Integer, primary_key=True, index=True)
    title: str = Column(String(255), nullable=False)
    fileId: int = Column(Integer, nullable=False)
    create_at: TIMESTAMP = Column(TIMESTAMP, default=datetime.now(timezone.utc), nullable=False)
    totalCount: int = Column(Integer, nullable=False)